<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-calendar"></i> 运单
                </el-breadcrumb-item>
                <el-breadcrumb-item>添加运单</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container" >
            <div class="form-box1" style="margin-left: 30%;margin-right: 30%;margin-top: 5%;">
                <br><br>
                <el-form ref="form" :model="form" label-width="100px" style="margin-left: 120px;">
                    <el-form-item label="运单号">
                        <el-input v-model="form.order_id" style="width: 150px;"></el-input>
                        <el-button style="width: 100px;" @click='getorder'>点我生成单号</el-button>
                    </el-form-item>
                    <el-form-item label="客户名称">
                        <el-select v-model="form.contacts" style="width: 250px;">
                            <el-option
                                v-for="item in options_user"
                                :key="item.id"
                                :label="item.contacts"
                                :value="item.id"
                                >
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="货物类型">
                        <el-select v-model="form.good" style="width: 250px;">
                            <el-option
                                v-for="item in options"
                                :key="item.id"
                                :label="item.gname"
                                :value="item.id"
                                >
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="发货城市：">
                        <el-input v-model="form.city1" style="width: 250px;"></el-input>
                    </el-form-item>
                    <el-form-item label="发货地址：">
                        <el-input v-model="form.address1" style="width: 250px;"></el-input>
                    </el-form-item>
                    <el-form-item label="收货城市：">
                        <el-input v-model="form.city" style="width: 250px;"></el-input>
                    </el-form-item>
                    <el-form-item label="收货地址：">
                        <el-input v-model="form.address" style="width: 250px;"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="tianjia">添加运单</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
            </div>
        </div>
    </div>
</template>

<script>
    import{ gettag,addtag,getorder_id,addorder } from '../../api/api'
export default {
    name: 'baseform',
    data() {
        return {
            form: {
                good:"",  //货物类型
                phone:'',
                address1:'银川市兴庆区塞上骄子', //发货地址     正常应该是自动获取当前位置，目前写死
                address:'银川市金凤区水岸观邸', //收货地址
                city1:'银川市',    //发货城市       正常应该是自动获取当前位置，目前写死
                city:'银川市',    //收货城市
                contacts:'',//客户名称
                order_id:'',//订单号
            },
            options: [
                {
                    value: '1',
                    label: '公司一'
                    }, {
                    value: '2',
                    label: '公司二'
                    }, {
                    value: '3',
                    label: '公司三'
                    }, {
                    value: '4',
                    label: '公司四'
                },
            ],
            options_user: [
                {
                    value: '1',
                    label: '用户一'
                    }, {
                    value: '2',
                    label: '用户二'
                    }, {
                    value: '3',
                    label: '用户三'
                    }, {
                    value: '4',
                    label: '用户四'
                },
            ],
            
        };
    },
    methods: {
        tianjia(){
            var params = {
                order_id:this.form.order_id,        //订单号
                city:this.form.city,            //收货城市
                address:this.form.address,      //收货地址
                city1:this.form.city1,          //发货城市
                address1:this.form.address1,    //发货地址
                contacts:this.form.contacts,    //客户名称
                good:this.form.good,    //货物类型
            }
            console.log(params)
            addorder(params).then(res=>{
                this.$message.success(res.message);
            })
        },
        getorder(){
            getorder_id().then(res=>{
                console.log(res)
                this.form.order_id = res.order_id
            })
        }
    },
    mounted() {
        gettag().then(res=>{
            // console.log(res)
            this.options = res.gooddata
            this.options_user = res.customersdata
            console.log(res.customersdata)
        })
    },
};
</script>

<style>
.form-box1 {
        border: honeydew 1px solid;
        border-radius: 4px;
        box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
        margin-left: 30%;
        margin-right: 30%;
        margin-top: 5%;
    }
</style>